// Copyright (C) ZHENG Zhong <heavyzheng nospam-at gmail D0T com>
// http://www.zhengzhong.net/
//
// $Id: error_info.hpp 318 2009-03-02 14:03:21Z heavyzheng $
//

#ifndef ZZHENG_XML_SAX_ERROR_INFO_HPP_20090122__
#define ZZHENG_XML_SAX_ERROR_INFO_HPP_20090122__

#include <zzheng/xml/config.hpp>
#include <zzheng/xml/sax/types.hpp>
#include <zzheng/xml/sax/exception.hpp>

#ifdef ZZHENG_MSVC
#  pragma warning(push)
#  pragma warning(disable: 4127 4511 4512)
#endif // ZZHENG_MSVC

#include <boost/lexical_cast.hpp>

#ifdef ZZHENG_MSVC
#  pragma warning(pop)
#endif // ZZHENG_MSVC

#include <string>


namespace zzheng {
namespace xml {
namespace sax {

    class error_info {

    public:

        //! Default constructor.
        explicit error_info(): message(), file(), line(0U), column(0U) {
            // Do nothing.
        }

        explicit error_info(const std::string& message)
        : message(message), file(), line(0U), column(0U) {
            // Do nothing.
        }

        explicit error_info(const std::string& message,
                            const std::string& file,
                            size_type line,
                            size_type column)
        : message(message), file(file), line(line), column(column) {
            // Do nothing.
        }

        // Use auto-generated copy constructor.
        // Use auto-generated copy assignment.
        // Use auto-generated destructor.

        //! Returns a string representation of this error.
        //! \return a string representation of this error.
        std::string str() const {
            std::string str = (message.empty() ? "error message not available." : message);
            if (!file.empty()) {
                str.append(" in '").append(file).append("'");
                if (line > 0 && column > 0) {
                    str.append(" [")
                       .append(boost::lexical_cast<std::string>(line))
                       .append(":")
                       .append(boost::lexical_cast<std::string>(column))
                       .append("]");
                }
            }
            return str;
        }

        //! Returns a sax_error exception object to wrap the error info.
        //! \return a sax_error exception object to wrap the error info.
        sax_error exc() const {
            std::string what = str();
            return sax_error(what.c_str());
        }

    public:

        std::string message;
        std::string file;
        size_type   line;
        size_type   column;

        // TODO: std::string public_id_;
        // TODO: std::string system_id_;

    }; // class error_info


} // namespace zzheng::xml::sax
} // namespace zzheng::xml
} // namespace zzheng


#endif // ZZHENG_XML_SAX_ERROR_INFO_HPP_20090122__




